main(c,d){for(gets(&c);~scanf("%d%d%d%d",&d,&d,&c,&d);printf("%d\n",d%c?d+d-c:d/c*d));}
